﻿using UnityEngine;
using UnityEngine.UI;

namespace XFGameFramework.TweenSystem
{
    /// <summary>
    /// Image动画拓展
    /// </summary>
    public static class ImageExtensions 
    {

        /// <summary>
        /// 渐变FillAmount
        /// </summary>
        /// <param name="image"></param>
        /// <param name="target">目标fillAmount</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义的缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>
        public static TweenerCore<float> TweenFillAmount(this Image image, float target, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false,float delay = 0, int loopCount = -1)
        { 
            return TweenManager.ComponentTween(image, image.fillAmount, target, duration, loop, ease, curve, ingoreTimeScale, OnTweenFillAmount, delay, 0, loopCount);
        }


        internal static void OnTweenFillAmount(TweenerCore<float> tweener) 
        {
            if (tweener.Component is Image) 
            {
                Image image = tweener.Component as Image;
                image.fillAmount = tweener.Value;
            }
        }
        
    }

}

